package historyElemente;

import java.awt.Font;
import java.awt.Graphics;

public class HistoryHtmlString implements HistoryElement{
	
	private String string;
	private Tag tag;
	
	public HistoryHtmlString(String s, Tag t){
		this.string = s;
		this.tag = t;
	}
	

	@Override
	public void drawElement(Graphics g, int x, int y) {
		Font old = g.getFont();
		switch(tag){
		case BOLD:
			g.setFont(new Font(old.getFontName(), Font.BOLD, old.getSize()));
			break;
		case ITALIC:
			g.setFont(new Font(old.getFontName(), Font.ITALIC, old.getSize()));
			break;
		case UNDERLINED:
			g.drawLine(x, y, x+g.getFontMetrics().stringWidth(string), y);
			break;
		default:
			break;
		}
		g.drawString(string, x, y);
		g.setFont(old);
		
	}

	@Override
	public int getWidth(Graphics g) {
		Font old = g.getFont();
		int width = 0;
		switch(tag){
		case BOLD:
			g.setFont(new Font(old.getFontName(), Font.BOLD, old.getSize()));
			break;
		case ITALIC:
			g.setFont(new Font(old.getFontName(), Font.ITALIC, old.getSize()));
			break;
		case UNDERLINED:
			break;
		default:
			break;
		}	
		width = g.getFontMetrics().stringWidth(string);
		g.setFont(old);
		return width;
	}

}
